home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / I386 / IIS5_01.CAB / IIS_FundTransfer_VBScript.asp < prev    next >
Encoding:
Text File  |  1998-09-16  |  3.1 KB  |  104 lines

  1. <%@ TRANSACTION = Required LANGUAGE = "VBScript" %>
  2. <% Option Explicit %>
  3.  
  4. <!*************************
  5. This sample is provided for educational purposes only. It is not intended to be 
  6. used in a production environment, has not been tested in a production environment, 
  7. and Microsoft will not provide technical support for it. 
  8. *************************>
  9.  
  10. <!--METADATA TYPE="typelib" 
  11. FILE="c:\program files\common files\system\ado\msado15.dll" -->
  12.  
  13. <HTML>
  14.     <HEAD>
  15.         <TITLE>Transactional Database Update</TITLE>
  16.     </HEAD>
  17.  
  18.     <BODY BGCOLOR="White" TOPMARGIN="10" LEFTMARGIN="10">
  19.  
  20.  
  21.         <!-- DISPLAY HEADER -->
  22.  
  23.         <FONT SIZE="4" FACE="ARIAL, HELVETICA">
  24.         <B>Transactional Database Update</B></FONT><BR>
  25.       
  26.         <HR SIZE="1" COLOR="#000000">
  27.  
  28.  
  29.         <!-- Brief Description blurb.  -->
  30.  
  31.         This is a simple example demonstrating how to transactionally 
  32.         update a SQL 6.5 database using ADO and Transacted ASP.
  33.         The example will obtain information regarding a book price from 
  34.         the SQL 6.5 "Pubs" database.  It will mark up 10% of the
  35.         first book price and mark donw 10% of the second book price. 
  36.  
  37.         <p> Because the two database operations are wrapped
  38.         within a shared ASP Transaction, both will be automatically rolled
  39.         back to their previous state in the event of a failure.
  40.  
  41.  
  42.     <%
  43.         Dim objConn        ' object for ADODB.Connection obj
  44.         Dim objRs            ' object for recordset object
  45.         Dim strTitleID        
  46.  
  47.         ' Create Connection and Recordset components.
  48.  
  49.         Set objConn = Server.CreateObject("ADODB.Connection")
  50.         Set objRs   = Server.CreateObject("ADODB.Recordset")
  51.  
  52.         'Connection string is OLEDB type instead of ODBC
  53.         ' Open ADO Connection using account "sa"
  54.         ' and blank password.
  55.  
  56.         objConn.Open "Provider=SQLOLEDB;User ID=sa;Initial Catalog=pubs;Data Source="& Request.ServerVariables("SERVER_NAME")
  57.         Set objRs.ActiveConnection = objConn
  58.         Set objRs2.ActiveConnection = objConn
  59.  
  60.  
  61.  
  62.         ' query title id
  63.  
  64.         objRs.Source = "SELECT title_id FROM Titles"
  65.         objRs.CursorType = adOpenForwardOnly            ' use a cursor Forward Only.
  66.         objRs.LockType = adLockReadOnly                    ' use a locktype ReadOnly.
  67.         objRs.Open
  68.  
  69.         'Get first title,  mark up price by 10% 
  70.  
  71.         If (Not objRs.EOF) Then
  72.           strTitleID=objRs("title_id").Value
  73.           objConn.Execute "Update titles Set price =price+ price*(0.1) where title_id = "& strTitleID 
  74.         End If
  75.         
  76.         'Get first title,  mark up price by 10% 
  77.         objRs.MoveNext
  78.         If (Not objRs.EOF) Then
  79.           strTitleID=objRs("title_id").Value
  80.           objConn.Execute "Update titles Set price =price- price*(0.1) where title_id = "& strTitleID 
  81.         End If
  82.     %>
  83.  
  84.  
  85.     </BODY>
  86. </HTML>
  87.  
  88.  
  89. <%
  90.     ' The Transacted Script Commit Handler.  This sub-routine
  91.     ' will be called if the transacted script commits.
  92.  
  93.     Sub OnTransactionCommit()
  94.         Response.Write "<P><B>The update was successful</B>." 
  95.     End Sub
  96.  
  97.  
  98.     ' The Transacted Script Abort Handler.  This sub-routine
  99.     ' will be called if the script transacted aborts
  100.  
  101.     Sub OnTransactionAbort()
  102.         Response.Write "<P><B>The update was not successful</B>." 
  103.     End Sub
  104. %>